package com.hs.srm.admin.modules.requisition.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.orders.entity.ScmPoHeaderEntity;
import com.hs.srm.admin.modules.orders.entity.ScmPoItemEntity;
import com.hs.srm.admin.modules.requisition.dao.SamplePurchRequestHeaderDao;
import com.hs.srm.admin.modules.requisition.dao.SamplePurchRequestItemDao;
import com.hs.srm.admin.modules.requisition.entity.SamplePurchRequestHeaderEntity;
import com.hs.srm.admin.modules.requisition.service.SamplePurchRequestHeaderService;
import com.hs.srm.admin.modules.requisition.service.SamplePurchRequestItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ych
 * @since 2020-05-09 09:12:05
 */
@Service("samplePurchRequestHeaderService")
public class SamplePurchRequestHeaderServiceImpl extends ServiceImpl<SamplePurchRequestHeaderDao, SamplePurchRequestHeaderEntity> implements SamplePurchRequestHeaderService {

    @Autowired
    private SamplePurchRequestHeaderDao samplePurchRequestHeaderDao;
    @Autowired
    private SamplePurchRequestItemDao samplePurchRequestItemDao;

    /**
     * 根据采购申请单号查询
     *
     * @param purchRequestCode
     * @return
     */
    @Override
    public SamplePurchRequestHeaderEntity findByNo(String purchRequestCode) {
        SamplePurchRequestHeaderEntity headerEntity = this.selectOne(new EntityWrapper<SamplePurchRequestHeaderEntity>().eq("purch_request_code", purchRequestCode));
        return headerEntity;
    }

    /**
     * 改变货源状态
     *
     * @param goodsStatus
     * @param requestCode
     * @return
     */
    @Override
    public boolean changeGoodsStatus(int goodsStatus, String requestCode) {
        SamplePurchRequestHeaderEntity headerEntity = new SamplePurchRequestHeaderEntity();
        headerEntity.setGoodsStatus(goodsStatus);
        int rows = this.baseMapper.update(headerEntity, new EntityWrapper<SamplePurchRequestHeaderEntity>()
                .eq("purch_request_code", requestCode));
        return rows > 0 ? true : false;
    }

    @Override
    public List<ScmPoHeaderEntity> findPoNo() {
        return this.samplePurchRequestHeaderDao.findPoNo();
    }

    @Override
    public List<ScmPoItemEntity> findItemPoNo() {
        return this.samplePurchRequestItemDao.findItemPoNo();
    }
}